package com.bdqn.Di1Zhan;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class AccessPersonConstructors {
    public static void main(String[] args) {
        try {
            Class slz = Class.forName("reflect.entity.person");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }catch (SecurityException e){
            e.printStackTrace();
        }catch (IllegalArgumentException e){
            e.printStackTrace();
        }catch (InstantiationError e){
            e.printStackTrace();
        }catch (IllegalAccessError e){
            e.printStackTrace();
        }

        try {
            Class clz = Class.forName("reflect.entity.person");
            Object object = clz.newInstance();
            System.out.println(object);

            Constructor c1 = clz.getDeclaredConstructor();

            object = c1.newInstance();
            System.out.println(object);

            Constructor c2 = clz.getDeclaredConstructor(String.class);

            c2.setAccessible(true);
            object = c2.newInstance("New Person");
            System.out.println(object);
            Constructor c3 = clz.getDeclaredConstructor(String.class , String.class , String.class );
            c3.setAccessible(true);
            object = c3.newInstance("New Person" , "beijing","Hello");
            System.out.println(object);
        }catch (ClassNotFoundException e){
            e.printStackTrace();
        }catch (SecurityException e){
            e.printStackTrace();
        }catch (NoSuchMethodException e){
            e.printStackTrace();
        }catch (IllegalArgumentException e){
            e.printStackTrace();
        }catch (InstantiationException e){
            e.printStackTrace();
        }catch (IllegalAccessException e){
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
